import { Shape } from "./Shape";
import { Container } from "./Container";

export abstract class BaseLayer extends Container<Shape> {
  canvas: HTMLCanvasElement = document.createElement("canvas");
  hitCanvas: HTMLCanvasElement;

  _waitingForDraw = false; // 绘制状态

  // 获取图层
  getLayer(): BaseLayer | null {
    return this;
  }
  // 获取canvas上下文对象
  getContext() {
    return this.canvas.getContext("2d");
  }
  getHitCanvas() {
    return this.hitCanvas;
  }
  getHitContext() {
    return this.hitCanvas.getContext("2d");
  }
  getIntersection(pos) {
    return null;
  }
  // 重绘
  batchDraw() {
    if (!this._waitingForDraw) {
      this._waitingForDraw = true;
      requestAnimationFrame(() => {
        this.draw();
        this._waitingForDraw = false;
      });
    }
  }
}
